package com.jeejio.common.util

import android.view.View

object ViewExtension {
    private const val MIN_CLICK_INTERVAL = 500L

    fun View.setOnPreventRepeatClickListener(onClickInterval: Long = MIN_CLICK_INTERVAL, onPreventRepeatOnClickListener: (View?) -> Unit) {
        var lastOnClickTime = System.currentTimeMillis()
        setOnClickListener { v ->
            if (System.currentTimeMillis() - lastOnClickTime < onClickInterval) {
                return@setOnClickListener
            }
            lastOnClickTime = System.currentTimeMillis()
            onPreventRepeatOnClickListener.invoke(v)
        }
    }
}